package com.heyun.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heyun.bean.HeyunSchedule;
import com.heyun.service.impl.ScheduleServiceImpl;

@Controller
public class ScheduleController {

	@Autowired
	private ScheduleServiceImpl scheduleServiceImpl;

	/**
	 *model modelMap  modelandview 
	 *
	 */
	@RequestMapping("/schedule")
	@ResponseBody
	public Map cusList(String pageNum){
		
		Map map=new HashMap();
		Page page=PageHelper.startPage(Integer.valueOf(pageNum), 2);
		
		List schList=scheduleServiceImpl.findSchedule();
		int totals=page.getPages();
		map.put("totalPages", totals);
		map.put("schList", schList);
		 return map; 
		
	
}
	
	@RequestMapping("/addSchedule")
	@ResponseBody
	public Map saveSchedule(HeyunSchedule sc){
		Map map=new HashMap<>();
		int m=scheduleServiceImpl.saveSchedule(sc);

		 if(m>0){
			 map.put("message", "添加成功");
		 }else{
			 map.put("message", "系统出错，请重新操作");
		 }
		  return map;
		
	}
	@RequestMapping("/updateSchedule")
	@ResponseBody
	public Map updateSchedule(HeyunSchedule sch){
		Map map=new HashMap<>();
		int m=scheduleServiceImpl.updateSchedule(sch);
		 if(m>0){
			 map.put("message", "添加成功");
		 }else{
			 map.put("message", "系统出错，请重新操作");
		 }
		  return map;
		
	}
	
	@RequestMapping("/selSchedule")
	@ResponseBody
	public Map<String,HeyunSchedule> selSchedule(String schId){
		Map<String,HeyunSchedule> map=new HashMap<String,HeyunSchedule>();
		
		int id=Integer.parseInt(schId);
		
		HeyunSchedule sch=scheduleServiceImpl.selSchedule(id);
        map.put("sch",sch);
		 return map; 
	}
	
	@RequestMapping("/delSchedule")
	@ResponseBody
	public Map delSchedule(String schId){
		Map map=new HashMap<>();
		int id=Integer.parseInt(schId);
		int m=scheduleServiceImpl.delSchedule(id);
		 if(m>0){
			 map.put("message", "删除成功");
		 }else{
			 map.put("message", "系统出错，请重新操作");
		 }
		  return map;
		
	}
	@RequestMapping("/selectByMonth")
	@ResponseBody
	public Map selectByCondition(HeyunSchedule sch,String pageNum){
		System.out.println(pageNum);
		Map map=new HashMap();
		List<HeyunSchedule> schList=scheduleServiceImpl.selectByMonth(sch);
		Page page=PageHelper.startPage(Integer.valueOf(pageNum), 2);
		int totals=page.getPages();
		map.put("totalPages", totals);
		map.put("schList",schList);
		return map;
		
	}
}
